import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/resources.dart';
import 'package:ls_work/ui/service_execute/service_statitscs_fragment.dart';

import '../../res/colors.dart';
import '../../viewmodel/service_execute/service_execute_home_statistics_view_model.dart';
import '../../widgets/my_sliver_delegate.dart';

class ServiceExecuteStatisticsHomePage extends BaseStatefulMvvmWidget {
  bool useNew = false;

  ServiceExecuteStatisticsHomePage({this.useNew = false});

  @override
  State<StatefulWidget> createState() => _ServiceExecuteStatisticsHomeState();
}

class _ServiceExecuteStatisticsHomeState extends BaseMvvmState<
    ServiceExecuteHomeStatisticsViewModel, ServiceExecuteStatisticsHomePage> {
  List<PickerDataWithIdModel> get titles => [
        PickerDataWithIdModel(pickName: '未完成', pickId: '0'),
        PickerDataWithIdModel(pickName: '已完成', pickId: '1'),
      ];

  @override
  Widget buildLoadingContentView() {
    return Stack(
      children: [
        DefaultTabController(
            length: 2,
            child: NestedScrollView(
                headerSliverBuilder: (context, bool) {
                  return [
                    SliverToBoxAdapter(
                      child: Stack(
                        alignment: Alignment.center,
                        children: [
                          Row(
                            children: [
                              Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  CommonText(viewModel.data.total,
                                      textColor: Colors.black,
                                      textSize: 24,
                                      fontWeight: FontWeight.bold),
                                  Container(
                                    height: 15,
                                  ),
                                  CommonText('今日任务数')
                                ],
                              ).setWeight(1),
                              Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  CommonText(viewModel.data.hasServed,
                                      textSize: 24,
                                      textColor: Color(0xff00b3f6),
                                      fontWeight: FontWeight.bold),
                                  Container(
                                    height: 15,
                                  ),
                                  CommonText('已服务')
                                ],
                              ).setWeight(1),
                              Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  CommonText(viewModel.data.notServed,
                                      textSize: 24,
                                      textColor: Color(0xfff6ab00),
                                      fontWeight: FontWeight.bold),
                                  Container(
                                    height: 15,
                                  ),
                                  CommonText('待服务')
                                ],
                              ).setWeight(1)
                            ],
                          )
                        ],
                      ).addToContainer(
                          width: double.infinity,
                          height: 108,
                          decoration: BoxDecoration(
                            color: Colors.white,
                          )),
                    ),
                    SliverToBoxAdapter(
                      child: Gaps.line,
                    ),
                    SliverPersistentHeader(
                        pinned: true,
                        delegate: MySliverDelegate(
                            maxHeight: 40,
                            minHeight: 40,
                            child: Material(
                              color: Colors.white,
                              child: TabBar(
                                labelColor: Colors.black,
                                unselectedLabelColor: Color(0xff545454),
                                indicatorColor: Colours.app_main,
                                indicatorSize: TabBarIndicatorSize.label,
                                labelStyle: TextStyle(
                                    fontWeight: FontWeight.bold, fontSize: 18),
                                unselectedLabelStyle: TextStyle(
                                    fontSize: 16,
                                    fontWeight: FontWeight.normal),
                                tabs: titles
                                    .map((e) => Tab(
                                          text: e.pickName,
                                        ))
                                    .toList(),
                              ),
                            )))
                  ];
                },
                body: TabBarView(
                  children: titles
                      .map((e) => ServiceStatisticsFragment(
                            e.pickId!,
                            useNew: widget.useNew,
                          ))
                      .toList(),
                ))),
        ElevatedButton(
          onPressed: () {
            viewModel.scanCode();
          },
          child: CommonText('扫码', textColor: Colors.white),
          style: ButtonStyle(
              backgroundColor: WidgetStateProperty.all(Colours.app_main),
              shape: WidgetStateProperty.all(StadiumBorder()),
              minimumSize:
                  WidgetStateProperty.all(Size(double.infinity, 45))),
        ).setLocation(bottom: 10, left: 16, right: 16)
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Color(0xfff1f1f1),
      appBar: AppBar(
        title: Text('照护实施'),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  ServiceExecuteHomeStatisticsViewModel createViewModel() {
    return ServiceExecuteHomeStatisticsViewModel(context);
  }

  @override
  void onRetryClick() {}
}
